package ch01;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/pinfo-result")
public class PersonalInfoServlet extends HttpServlet {    
    private String noticeToHangul(String notice){
    	if(notice == null) return "받지 않음";
    	else if(notice.equals("on")) return "받음";
    	else return notice;    	
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String id = request.getParameter("id");
		String password = request.getParameter("password");
		String gender = request.getParameter("gender");
		if(gender.equals("male")) gender = "남";
		else gender ="여";
		String[] locs = request.getParameterValues("loc");
		String inotice = request.getParameter("inotice");
		String cnotice = request.getParameter("cnotice");
		String dnotice = request.getParameter("dnotice");
		String job = request.getParameter("job");
		
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		out.println("<title>개인정보 - 결과</title>");
		out.printf("이름: %s <br>",name);
		out.printf("아이디: %s <br>",id);
		out.printf("암호: %s <br>",password);
		out.printf("성별: %s <br>",gender);
		out.print("선호 지역: ");
		for(String loc:locs) out.print(loc+" ");
		out.print("<br>");
		out.printf("공지메일: %s <br>",noticeToHangul(inotice));
		out.printf("광고메일: %s <br>",noticeToHangul(cnotice));
		out.printf("배송확인메일: %s <br>",noticeToHangul(dnotice));		
		out.printf("직업: %s <br>",job);
	}
}
